/**
 * @Author xieha
 * @Email xiehao35755@163.com
 * @Date 2020-02-16 16:58
 */


package com.xh.blog.common.wrapper;

import com.xh.blog.common.enums.ResponseCodeEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * Created by xieha on 2020-02-16.
 */
@Data
public class ResponseWrapper<T> implements Serializable {
    private int code;
    private String msg;
    private T data;
    public ResponseWrapper<T> success(T data){

        ResponseWrapper<T> response = new ResponseWrapper();
        response.setData(data);
        response.setCode(ResponseCodeEnum.SUCCESS.code());
        response.setMsg(ResponseCodeEnum.SUCCESS.msg());
        return response;
    }

    public ResponseWrapper<T> error(T data){
        ResponseWrapper<T> response = new ResponseWrapper();
        response.setData(data);
        response.setCode(ResponseCodeEnum.ERROR.code());
        response.setMsg(ResponseCodeEnum.ERROR.msg());
        return response;
    }

    public ResponseWrapper<T> error(T data,int code,String msg){
        ResponseWrapper<T> response = new ResponseWrapper();
        response.setData(data);
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }
    public static ResponseWrapper getInstance(){
        return new ResponseWrapper();
    }
}
